from django.shortcuts import render

# Create your views here.
from django.shortcuts import render
from .models import Article
from django.core.paginator import Paginator


# Create your views here.
# 编辑页显示
def edit_article(request):
    return render(request, 'editArticle_.html')


# 数据列表页显示
def page_list(request):
    if request.method == 'POST':
        # 获取页面信息
        title = request.POST['title']
        time = request.POST['time']
        desc = request.POST['desc']
        print('页面信息：', title, time, desc)
        # 写入数据库
        a = Article.objects.create(
            title=title, time=time, desc=desc
        )


    # 数据分页
    # 查询数据集
    content = Article.objects.all()
    # 设置每页显示2个对象
    per_page = 2
    # 创建Paginator对象
    paginator = Paginator(content, per_page)
    # 从GET请求中获取页码
    page_number = request.GET.get('page')
    # 获取具体页码的page对象
    page_obj = paginator.get_page(page_number)
    # 将page对象传递到模板中
    return render(request, 'list_.html', {'page_obj': page_obj})








